<template>
  <el-dialog v-model="dialogFormVisible" :title="title" width="800">
    <el-form :model="form" label-width="auto" style="max-width: 800px">
      <div class="form-scroll">
        <el-row :gutter="20">
          <template v-for="(item, index) in Object.keys(form)">
            <template v-if="item !== '检验列表'">
              <el-col :span="12">
                <el-form-item :label="item">
                  <template v-if="form[item].type === 'datetime'">
                    <el-date-picker
                      v-model="form[item].value"
                      type="date"
                      :placeholder="`请选择${item}`"
                      value-format="YYYY-MM-DD"
                    />
                  </template>
                  <template v-else>
                    <el-input v-model="form[item].value" :placeholder="`请填写${item}`" />
                  </template>
                </el-form-item>
              </el-col>
            </template>
            <template v-else>

            </template>
          </template>
        </el-row>
      </div>
    </el-form>
    <div>
      <el-button type="primary" @click="onSubmit">{{ isEdit? '编辑': '新增' }}</el-button>
      <el-button @click="dialogFormVisible = false">取消</el-button>
    </div>
  </el-dialog>
</template>

<script setup>
  // 方法
  import { ref, defineExpose } from 'vue'

  // 显示表单
  const dialogFormVisible = ref(false)
  const title = ref('新增采样点')
  const isEdit = ref(false)
  // 表单
  const form = ref({
    '采样点名称': { type: '', value:  '' },
    '采样点地址': { type: '', value:  '' },
    '经度': { type: '', value:  '' },
    '纬度': { type: '', value:  '' },
    '备注': { type: '', value:  '' },
  })

  // 打开方法
  const open = () => {
    dialogFormVisible.value = true
    isEdit.value = false
    title.value = '新增采样点'
  }
  // 编辑
  const edit = () => {
    isEdit.value = true
    dialogFormVisible.value = true
    title.value = '编辑采样点'
  }
  // 关闭方法
  const close = () => {
    dialogFormVisible.value = false
  }

  // 提交
  const onSubmit = () => {

  }

  defineExpose({
    open, close, edit
  })

</script>

<style scoped lang="scss">

</style>
